package Week.D007;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class Solution02 {

    public class FileSystem {
        private Map<String,Integer> fileMap;
        public FileSystem() {
            fileMap=new HashMap<>();
        }

        public boolean create(String path, int value) {
            if(path.charAt(0)!='/'){
                return false;
            }
            if(fileMap.containsKey(path)){
                return false;
            }
            int index=path.lastIndexOf("/");
            String parentPath=path.substring(0,index);
            if(!fileMap.containsKey(parentPath)&&parentPath.length()!=0){
                return false;
            }
            fileMap.put(path,value);
            return true;

        }

        public int get(String path) {
            if(!fileMap.containsKey(path)){
                return -1;
            }
            return fileMap.get(path);

        }

        @Test
        public void test(){
            String path="01234567";
            String parentPath=path.substring(0,2);
            System.out.println(parentPath);
        }
    }
}
